package com.jiutong.meipengdai.http.present;

import android.content.Context;

import com.jiutong.meipengdai.entity.BankCardListRespond;
import com.jiutong.meipengdai.entity.BankInfoRespond;
import com.jiutong.meipengdai.entity.BaseRespond;
import com.jiutong.meipengdai.http.model.interfaces.BankListBiz;
import com.jiutong.meipengdai.http.model.requests.MyAccountRequest;
import com.jiutong.meipengdai.http.subscribers.ProgressSubscriber;
import com.jiutong.meipengdai.http.subscribers.SubscriberOnNextListener;

import java.util.HashMap;

/**
 * Created by suxi on 2017/6/20.
 */

public class BankListPresent {

    private final Context mContext;
    private final BankListBiz mBankListBize;
    private final MyAccountRequest mapRequest;

    public BankListPresent(Context context, BankListBiz bankListBiz){
        this.mContext = context;
        this.mBankListBize = bankListBiz;
        mapRequest = new MyAccountRequest();
    }

    /**
     * 添加银行卡
     */
    public void addBannkInfo() {
        SubscriberOnNextListener onNextListener = new SubscriberOnNextListener<BaseRespond>() {
            @Override
            public void onNext(BaseRespond subjects) {
                mBankListBize.onSuccess(subjects);
            }

            @Override
            public void onError(Throwable e) {
                mBankListBize.onError(e);
            }
        };

        HashMap<String, Object> fieldsMap = new HashMap<>();
        fieldsMap.put("bankNumber", mBankListBize.getBankNumber());
        fieldsMap.put("phoneNo", mBankListBize.getPhoneNo());
        mapRequest.addBannkInfo(new ProgressSubscriber(onNextListener, mContext), fieldsMap);
    }

    /**
     * 银行卡列表
     */
    public void getBanklist() {
        SubscriberOnNextListener onNextListener = new SubscriberOnNextListener<BankCardListRespond>() {
            @Override
            public void onNext(BankCardListRespond subjects) {
                mBankListBize.onSuccess(subjects);
            }

            @Override
            public void onError(Throwable e) {
                mBankListBize.onError(e);
            }
        };

        HashMap<String, Object> fieldsMap = new HashMap<>();
        mapRequest.getBanklist(new ProgressSubscriber(onNextListener, mContext), fieldsMap);
    }


    /**
     * 银行卡详情
     */
    public void getBankInfo() {
        SubscriberOnNextListener onNextListener = new SubscriberOnNextListener<BankInfoRespond>() {
            @Override
            public void onNext(BankInfoRespond subjects) {
                mBankListBize.onSuccess(subjects);
            }

            @Override
            public void onError(Throwable e) {
                mBankListBize.onError(e);
            }
        };

        HashMap<String, Object> fieldsMap = new HashMap<>();
        fieldsMap.put("bankId", mBankListBize.getBankId());
        mapRequest.getBankInfo(new ProgressSubscriber(onNextListener, mContext), fieldsMap);
    }



    /**
     * 删除银行卡
     */
    public void delBannkInfo(SubscriberOnNextListener onNextListener, HashMap<String, Object> fieldsMap) {

//        HashMap<String, Object> fieldsMap = new HashMap<>();
//        fieldsMap.put("noAgree", mBankListBize.getBankId());

        mapRequest.delBannkInfo(new ProgressSubscriber(onNextListener, mContext), fieldsMap);
    }

}
